<template>
  <view class="mb-8px">
    <Card class="event-card">
      <template #header>
        <view class="flex p-16px justify-between">
          <view>
            <view class="font-size-15px font-extrabold height-6 line-height-6">
              <text>{{ props.category.name }}</text>
              <text class="ml-4px mr-4px">|</text>
              <text class="color-#3B6EFF">{{ props.event.name }}</text>
            </view>
            <view class="font-size-12px">
              {{ props.category.minAge }}-{{ props.category.maxAge }}岁
            </view>
          </view>
          <view class="flex items-center font-size-11px font-400 color-#909193">
            <!-- <text>不允许跨组参赛</text> -->
          </view>
        </view>
      </template>
      <view class="pl-8px pr-8px pb-8px">
        <!-- <block v-else> -->
        <block
          v-for="(stageItem, stageIndex) in props.event.stages"
          :key="stageIndex"
        >
          <view>
            <block v-if="stageItem.type === 1">
              <Card
                class="stage-card"
                wrapperStyle="background-color: #F4F4F5;margin-bottom: 8px;padding: 8px 12px;"
              >
                <template #header>
                  <view class="flex justify-between pt-8px pb-8px">
                    <view class="pt-8px pb-8px flex items-center">
                      <text class="font-size-20px font-400">{{
                        stageItem.name
                      }}</text>
                      <text class="font-size-14px font-400 ml-8px"></text>
                    </view>
                    <view
                      class="font-size-15px font-400 color-#F9AE3D flex items-center"
                    >
                      第{{ stageIndex + 1 }}阶段
                    </view>
                  </view>
                </template>
                <view class="flex flex-wrap pt-4px pb-4px">
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">人/队数</text>
                    <text>{{ stageItem.playerCount }}</text>
                  </view>
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">分赛制</text>
                    <text>{{ RallyTypeText[stageItem.rallyRuleId] }}</text>
                  </view>
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">晋级数量</text>
                    <text>{{ stageItem.eliminationWinnerCount }}</text>
                  </view>
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">局赛制</text>
                    <text>{{
                      MatchGameWinTypeText[stageItem.gameRuleId]
                    }}</text>
                  </view>
                </view>
                <template #footer>
                  <view
                    class="pb-8px pl-12px pr-12px flex justify-end h-80rpx items-center"
                  >
                    <wd-button
                      plain
                      hairline
                      size="small"
                      class="!ml-4px"
                      @click="
                        () => {
                          goEventDetail(stageItem);
                        }
                      "
                    >
                      查看比赛
                    </wd-button>

                    <wd-button
                      plain
                      hairline
                      size="small"
                      class="!ml-4px"
                      @click="
                        () => {
                          checkDetail(stageItem);
                        }
                      "
                    >
                      查看配置
                    </wd-button>
                    <wd-button
                      plain
                      hairline
                      type="error"
                      size="small"
                      class="!ml-4px"
                      @click="
                        () => {
                          removeStage(stageItem.id);
                        }
                      "
                    >
                      删除
                    </wd-button>
                  </view>
                </template>
              </Card>
            </block>
            <block v-else>
              <Card
                class="stage-card"
                wrapperStyle="background-color: #F4F4F5;margin-bottom: 8px;padding: 8px 12px;"
              >
                <template #header>
                  <view class="flex justify-between pt-8px pb-8px">
                    <view class="pt-8px pb-8px flex items-center">
                      <text class="font-size-20px font-400">{{
                        stageItem.name
                      }}</text>
                      <text class="font-size-14px font-400 ml-8px"></text>
                    </view>
                    <view
                      class="font-size-15px font-400 color-#F9AE3D flex items-center"
                    >
                      第{{ stageIndex + 1 }}阶段
                    </view>
                  </view>
                </template>
                <view class="flex flex-wrap pt-4px pb-4px">
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">人/队数</text>
                    <text>{{ stageItem.playerCount }}</text>
                  </view>
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">分赛制</text>
                    <text>{{ RallyTypeText[stageItem.rallyRuleId] }}</text>
                  </view>
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">每组出线人数</text>
                    <text>{{ stageItem.roundGroupWinnerCount }}</text>
                  </view>
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">局赛制</text>
                    <text>{{
                      MatchGameWinTypeText[stageItem.gameRuleId]
                    }}</text>
                  </view>
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">命名方式</text>
                    <text>{{
                      RoundNameTypeText[stageItem.roundNameType]
                    }}</text>
                  </view>
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">编排方式</text>
                    <text>{{
                      RoundOrganizationTypeText[stageItem.roundOrganizationType]
                    }}</text>
                  </view>
                  <view class="w-50% font-14px font-400 mb-4px">
                    <text class="color-#606266 mr-8px">循环次数</text>
                    <text>{{
                      RoundLoopTypeText[stageItem.roundLoopCount]
                    }}</text>
                  </view>
                </view>
                <template #footer>
                  <view
                    class="pb-8px pl-12px pr-12px flex justify-end h-80rpx items-center"
                  >
                    <wd-button
                      plain
                      hairline
                      size="small"
                      class="!ml-4px"
                      @click="
                        () => {
                          goEventDetail(stageItem);
                        }
                      "
                    >
                      查看比赛
                    </wd-button>

                    <wd-button
                      plain
                      hairline
                      size="small"
                      class="!ml-4px"
                      @click="
                        () => {
                          checkDetail(stageItem);
                        }
                      "
                    >
                      查看配置
                    </wd-button>
                    <wd-button
                      plain
                      hairline
                      type="error"
                      size="small"
                      class="!ml-4px"
                      @click="
                        () => {
                          removeStage(stageItem.id);
                        }
                      "
                    >
                      删除
                    </wd-button>
                  </view>
                </template>
              </Card>
            </block>
          </view>
        </block>

        <view
          v-if="true || !props.event.stages || !props.event.stages.length"
          class="w-100% pt-32px pb-32px h-44px flex justify-center items-center flex-col bg-#F4F4F5 mt-10px"
          @click="openChooseStagePopup"
        >
          <img class="size-14px" src="/static/app/icons/Vector.png " />
          <text class="font-15px">添加赛程</text>
        </view>
        <!-- </block> -->
      </view>
      <!-- <template #footer>
        <view
          v-if="props.event.stages.length < 2"
          class="pb-8px pl-12px pr-12px flex justify-end h-80rpx items-center"
        >
          <text class="font-size-17px font-400 color-#3B6EFF" @click="openChooseStagePopup">
            + 新增赛程
          </text>
        </view>
      </template> -->
    </Card>
    <wd-popup position="bottom" v-model="showChooseStagePopup" closable>
      <view class="w-100% pb-94px">
        <view class="h-64px flex justify-center items-center">新增赛程</view>
        <view
          class="h-46px flex justify-center items-center text-center"
          @click="toggleRoundStagePopup"
        >
          循环赛
        </view>
        <wd-divider></wd-divider>
        <view
          class="h-46px flex justify-center items-center text-center"
          @click="toggleEliminationPopup"
        >
          淘汰赛
        </view>
        <wd-divider></wd-divider>
      </view>
    </wd-popup>
    <wd-popup position="bottom" v-model="showRoundStagePopup" closable>
      <view class="h-64px flex justify-center items-center">创建循环赛</view>
      <wd-form ref="roundFormRef" :model="roundFormModel">
        <wd-cell-group border>
          <wd-input
            label="阶段名称"
            label-width="100px"
            prop="name"
            clearable
            v-model="roundFormModel.name"
            placeholder="请输入"
            :rules="[{ required: true, message: '阶段名称' }]"
            :disabled="roundFormReadonly"
          />
          <wd-input
            label="人/队数"
            label-width="100px"
            prop="playerCount"
            clearable
            v-model="roundFormModel.playerCount"
            placeholder="请输入"
            :rules="[{ required: true, message: '请输入人/队数' }]"
            :disabled="roundFormReadonly"
          />
          <wd-input
            label="分组数"
            label-width="100px"
            prop="roundGroupCount"
            clearable
            v-model="roundFormModel.roundGroupCount"
            placeholder="请输入"
            :rules="[{ required: true, message: '请输入分组数' }]"
            :disabled="roundFormReadonly"
          />
          <wd-input
            label="每组出现人/队数"
            label-width="100px"
            prop="roundGroupWinnerCount"
            clearable
            v-model="roundFormModel.roundGroupWinnerCount"
            placeholder="请输入"
            type="number"
            :disabled="roundFormReadonly"
          />
          <wd-picker
            :columns="matchGameWinColumns"
            label="局赛制"
            label-width="100px"
            prop="gameRuleId"
            v-model="roundFormModel.gameRuleId"
            placeholder="请选择"
            :disabled="roundFormReadonly"
          />
          <wd-cell title="是否打满局" title-width="100px">
            <wd-switch
              prop="mustFinishMaxCountGame"
              v-model="roundFormModel.mustFinishMaxCountGame"
              size="20"
              :disabled="roundFormReadonly"
            />
          </wd-cell>
          <wd-picker
            :columns="rallyTypeColumns"
            label="分赛制"
            label-width="100px"
            prop="rallyRuleId"
            v-model="roundFormModel.rallyRuleId"
            placeholder="请选择"
            :disabled="roundFormReadonly"
          />
          <wd-picker
            :columns="RoundNameTypeColumns"
            label="命名方式"
            label-width="100px"
            prop="roundNameType"
            v-model="roundFormModel.roundNameType"
            placeholder="请选择"
            :disabled="roundFormReadonly"
          />
          <wd-picker
            :columns="RoundOrganizationTypColumns"
            label="编排方式"
            label-width="100px"
            prop="roundOrganizationType"
            v-model="roundFormModel.roundOrganizationType"
            placeholder="请选择"
            :disabled="roundFormReadonly"
          />
          <wd-picker
            :columns="RoundLoopTypeColumns"
            label="循环次数"
            label-width="100px"
            prop="roundLoopCount"
            v-model="roundFormModel.roundLoopCount"
            placeholder="请选择"
            :disabled="roundFormReadonly"
          />
          <wd-input
            v-if="isTeamMatch"
            label="团队子比赛(需要精化)"
            label-width="100px"
            prop="stageEventTypes"
            v-model="roundFormModel.stageEventTypes"
            clearable
            placeholder="请输入"
            :disabled="roundFormReadonly"
          ></wd-input>
          <wd-cell
            v-if="isTeamMatch"
            title="是否打满子比赛"
            title-width="100px"
          >
            <wd-switch
              prop="mustFinishMaxCountMatch"
              v-model="roundFormModel.mustFinishMaxCountMatch"
              size="20"
              :disabled="roundFormReadonly"
            />
          </wd-cell>
          <wd-cell title="是否需要签到" title-width="100px">
            <wd-switch
              prop="mustCheckIn"
              v-model="eliminationFormModel.mustCheckIn"
              size="20"
              :disabled="eliminationFormReadonly"
            />
          </wd-cell>
          <wd-picker
            :columns="sourcePlayerStagesColumns"
            label="自动晋级阶段"
            label-width="100px"
            prop="playerSourceStageId"
            v-model="roundFormModel.playerSourceStageId"
            placeholder="请选择"
            :disabled="roundFormReadonly"
          />
          <wd-picker
            :columns="sourcePlayerTypeColumns"
            label="自动晋级类型"
            label-width="100px"
            prop="playerSourceType"
            v-model="roundFormModel.playerSourceType"
            placeholder="请选择"
            :disabled="roundFormReadonly || !roundFormModel.playerSourceStageId"
          />
        </wd-cell-group>
      </wd-form>
      <view class="flex m-20px">
        <wd-button
          class="flex-1 mr-10px"
          type="info"
          :round="false"
          @click="showRoundStagePopup = false"
        >
          取消
        </wd-button>
        <wd-button
          class="flex-1"
          type="primary"
          :round="false"
          @click="saveRoundStage"
          :disabled="roundFormReadonly"
        >
          保存
        </wd-button>
      </view>
    </wd-popup>
    <wd-popup position="bottom" v-model="showEliminationPopup" closable>
      <view class="h-64px flex justify-center items-center">创建淘汰赛</view>
      <wd-form :model="eliminationFormModel" ref="eliminationFormRef">
        <wd-cell-group border>
          <wd-input
            label="阶段名称"
            label-width="100px"
            prop="name"
            clearable
            v-model="eliminationFormModel.name"
            placeholder="请输入"
            :rules="[{ required: true, message: '阶段名称' }]"
            :disabled="eliminationFormReadonly"
          />
          <wd-input
            label="人/队数"
            label-width="100px"
            prop="playerCount"
            clearable
            v-model="eliminationFormModel.playerCount"
            placeholder="请输入"
            :rules="[{ required: true, message: '请输入人/队数' }]"
            :disabled="eliminationFormReadonly"
          />
          <wd-input
            label="晋级人数"
            label-width="100px"
            prop="eliminationWinnerCount"
            clearable
            v-model="eliminationFormModel.eliminationWinnerCount"
            placeholder="请输入"
            :disabled="eliminationFormReadonly"
          />
          <wd-picker
            :columns="matchGameWinColumns"
            label="局赛制"
            label-width="100px"
            prop="gameRuleId"
            v-model="eliminationFormModel.gameRuleId"
            placeholder="请选择"
            :disabled="eliminationFormReadonly"
          />
          <wd-cell title="是否打满局" title-width="100px">
            <wd-switch
              prop="mustFinishMaxCountGame"
              v-model="eliminationFormModel.mustFinishMaxCountGame"
              size="20"
              :disabled="eliminationFormReadonly"
            />
          </wd-cell>
          <wd-picker
            :columns="rallyTypeColumns"
            label="分赛制"
            label-width="100px"
            prop="rallyRuleId"
            v-model="eliminationFormModel.rallyRuleId"
            placeholder="请选择"
            :disabled="eliminationFormReadonly"
          />
          <wd-input
            label="签表顺序"
            label-width="100px"
            prop="eliminationSighType"
            clearable
            v-model="eliminationFormModel.eliminationSighType"
            placeholder="请输入"
            :disabled="eliminationFormReadonly"
          />
          <wd-input
            v-if="isTeamMatch"
            label="团队子比赛(需要精化)"
            label-width="100px"
            prop="stageEventTypes"
            v-model="eliminationFormModel.stageEventTypes"
            clearable
            placeholder="请输入"
            :disabled="eliminationFormReadonly"
          ></wd-input>
          <wd-cell
            v-if="isTeamMatch"
            title="是否打满子比赛"
            title-width="100px"
          >
            <wd-switch
              prop="mustFinishMaxCountMatch"
              v-model="eliminationFormModel.mustFinishMaxCountMatch"
              size="20"
              :disabled="eliminationFormReadonly"
            />
          </wd-cell>
          <wd-cell title="是否需要签到" title-width="100px">
            <wd-switch
              prop="mustCheckIn"
              v-model="eliminationFormModel.mustCheckIn"
              size="20"
              :disabled="eliminationFormReadonly"
            />
          </wd-cell>
          <wd-picker
            :columns="sourcePlayerStagesColumns"
            label="自动晋级阶段"
            label-width="100px"
            prop="playerSourceStageId"
            v-model="eliminationFormModel.playerSourceStageId"
            placeholder="请选择"
            :disabled="roundFormReadonly"
          />
          <wd-picker
            :columns="sourcePlayerTypeColumns"
            label="自动晋级类型"
            label-width="100px"
            prop="playerSourceType"
            v-model="eliminationFormModel.playerSourceType"
            placeholder="请选择"
            :disabled="
              roundFormReadonly || !eliminationFormModel.playerSourceStageId
            "
          />
        </wd-cell-group>
      </wd-form>
      <view class="flex m-20px">
        <wd-button
          class="flex-1 mr-10px"
          type="info"
          :round="false"
          @click="showEliminationPopup = false"
        >
          取消
        </wd-button>
        <wd-button
          class="flex-1"
          type="primary"
          :round="false"
          @click="saveEliminationStage"
          :disabled="eliminationFormReadonly"
        >
          保存
        </wd-button>
      </view>
    </wd-popup>
  </view>
</template>

<script setup lang="ts">
import { ref, defineProps } from "vue";
import Card from "./card.vue";
import {
  createStage,
  removeById,
  getGameRules,
  getRallyRules,
} from "@/service/stage";
import {
  EventTypeEnum,
  EventTypeText,
  RoundLoopTypeEnum,
  RoundLoopTypeText,
  RoundNameTypeEnum,
  RoundNameTypeText,
  RoundOrganizationEnum,
  RoundOrganizationTypeText,
  StagePlayerSourceTypeText,
  StageTypeEnum,
  TeamEventList,
} from "@/common/enum";
import {
  Category,
  EliminationStage,
  RoundStage,
  Event,
  GameRule,
  RallyRule,
} from "@/championship";

const props = defineProps<{
  category: Category;
  event: Event;
  onChange: () => void;
}>();

const showChooseStagePopup = ref(false);
const showRoundStagePopup = ref(false);
const showEliminationPopup = ref(false);
const isTeamMatch = ref(TeamEventList.includes(props.event.type));
const roundFormRef = ref(null);
const eliminationFormRef = ref(null);
// const rallyRules = ref([])
// const gameRules = ref([])
const roundFormModel = ref<RoundStage & { stageEventTypes?: string }>({});
const roundFormReadonly = ref(true);
const eliminationFormModel = ref<
  EliminationStage & { stageEventTypes?: string }
>({});
const eliminationFormReadonly = ref(true);
const matchGameWinColumns = ref<{ label: string; value: number }[]>([]);
const rallyTypeColumns = ref<{ label: string; value: number }[]>([]);
const RallyTypeText = ref<{ [id: number]: string }>({});
const MatchGameWinTypeText = ref<{ [id: number]: string }>({});
const sourcePlayerStagesColumns = ref<
  { label: string; value: number | string }[]
>([]);
const sourcePlayerTypeColumns = ref<{ label: string; value: number }[]>(
  Object.entries(StagePlayerSourceTypeText)
    .map(([key, value]) => ({
      label: value,
      value: parseInt(key),
    }))
    .sort((a, b) => b.value - a.value),
);

const RoundNameTypeColumns = ref(
  Object.entries(RoundNameTypeText).map(([key, value]) => ({
    label: value,
    value: key,
  })),
);
const RoundLoopTypeColumns = ref(
  Object.entries(RoundLoopTypeText).map(([key, value]) => ({
    label: value,
    value: key,
  })),
);
const RoundOrganizationTypColumns = ref(
  Object.entries(RoundOrganizationTypeText).map(([key, value]) => ({
    label: value,
    value: key,
  })),
);
const initDynamicOptions = async () => {
  (await getGameRules()).data.forEach((v) => {
    matchGameWinColumns.value.push({ label: v.name, value: v.id });
    MatchGameWinTypeText.value[v.id] = v.name;
  });
  (await getRallyRules()).data.forEach((v) => {
    rallyTypeColumns.value.push({ label: v.name, value: v.id });
    RallyTypeText.value[v.id] = v.name;
  });
};
watchEffect(() => {
  if (props.event && props.event.stages && props.event.stages.length > 0) {
    sourcePlayerStagesColumns.value = [];
    sourcePlayerStagesColumns.value.push({ label: "请选择", value: "" });
    props.event.stages.forEach((v) => {
      sourcePlayerStagesColumns.value.push({ label: v.name, value: v.id });
    });
  }
});

const initFormModel = async () => {
  await initDynamicOptions();
  roundFormModel.value = {
    name: "循环赛",
    roundGroupWinnerCount: 1,
    gameRuleId: matchGameWinColumns.value[0].value,
    rallyRuleId: rallyTypeColumns.value[0].value,
    roundNameType: RoundNameTypeEnum.alphabet,
    roundOrganizationType: RoundOrganizationEnum.ClockWise,
    roundLoopCount: RoundLoopTypeEnum.Single,
    mustFinishMaxCountGame: false,
    mustFinishMaxCountMatch: false,
    mustCheckIn: false,
    playerSourceType: null,
    playerSourceStageId: null,
  };
  eliminationFormModel.value = {
    name: "淘汰赛",
    eliminationWinnerCount: 1,
    gameRuleId: matchGameWinColumns.value[0].value,
    rallyRuleId: rallyTypeColumns.value[0].value,
    mustFinishMaxCountGame: false,
    mustFinishMaxCountMatch: false,
    mustCheckIn: false,
    playerSourceType: null,
    playerSourceStageId: null,
  };
};
const openChooseStagePopup = () => {
  showChooseStagePopup.value = true;
};
const toggleRoundStagePopup = async () => {
  // await initDynamicOptions()
  showRoundStagePopup.value = !showRoundStagePopup.value;
  showChooseStagePopup.value = false;
  if (showRoundStagePopup.value === true) {
    roundFormModel.value = {
      name: "循环赛",
      roundGroupWinnerCount: 1,
      gameRuleId: matchGameWinColumns.value[0].value,
      rallyRuleId: rallyTypeColumns.value[0].value,
      roundNameType: RoundNameTypeEnum.alphabet,
      roundOrganizationType: RoundOrganizationEnum.ClockWise,
      roundLoopCount: RoundLoopTypeEnum.Single,
      mustFinishMaxCountGame: false,
      mustFinishMaxCountMatch: false,
      mustCheckIn: false,
    };
    roundFormReadonly.value = false;
  }
};
const toggleEliminationPopup = async () => {
  // await initDynamicOptions()
  showEliminationPopup.value = !showEliminationPopup.value;
  showChooseStagePopup.value = false;
  if (showEliminationPopup.value === true) {
    eliminationFormModel.value = {
      name: "淘汰赛",
      eliminationWinnerCount: 1,
      gameRuleId: matchGameWinColumns.value[0].value,
      rallyRuleId: rallyTypeColumns.value[0].value,
      mustFinishMaxCountGame: false,
      mustFinishMaxCountMatch: false,
      mustCheckIn: false,
    };
    eliminationFormReadonly.value = false;
  }
};
const saveEliminationStage = async () => {
  const validateRes = await eliminationFormRef.value.validate();
  if (!validateRes.valid) {
    return;
  }
  const saveData = eliminationFormModel.value;
  saveData.type = 1;
  // saveData.name = '淘汰赛'
  saveData.playerType = 1;
  saveData.teamMatchType = 0;
  saveData.fkEventId = props.event.id;
  saveData.eventType = props.event.type;
  saveData.playerSourceStageId = saveData.playerSourceStageId || null;
  saveData.stageOrderInEvent = props.event.stages.length + 1;
  if (isTeamMatch.value && saveData.stageEventTypes) {
    saveData.stageEvents = saveData.stageEventTypes
      .split(",")
      .map((v, index) => {
        return {
          type: parseInt(v) as EventTypeEnum,
          eventOrder: index,
        };
      });
  }
  await createStage(saveData);
  // eliminationFormModel.value = {}
  // showEliminationPopup.value = false
  toggleEliminationPopup();
  props.onChange();
};
const saveRoundStage = async () => {
  const validateRes = await roundFormRef.value.validate();
  if (!validateRes.valid) {
    return;
  }
  const saveData = roundFormModel.value;
  // saveData.name = '循环赛'
  saveData.type = 2;
  saveData.playerType = 1;
  saveData.teamMatchType = 0;
  saveData.fkEventId = props.event.id;
  saveData.eventType = props.event.type;
  saveData.playerSourceStageId = saveData.playerSourceStageId || null;
  saveData.stageOrderInEvent = props.event.stages.length + 1;
  if (isTeamMatch.value && saveData.stageEventTypes) {
    saveData.stageEvents = saveData.stageEventTypes
      .split(",")
      .map((v, index) => {
        return {
          type: parseInt(v) as EventTypeEnum,
          eventOrder: index,
        };
      });
  }
  // saveData.stageEvents = saveData.stageEventTypes.split(',').map((v, index) => {
  //   return {
  //     type: parseInt(v) as EventTypeEnum,
  //     eventOrder: index,
  //   }
  // })
  await createStage(saveData);
  // roundFormModel.value = {}
  // showRoundStagePopup.value = false
  toggleRoundStagePopup();
  props.onChange();
};
const goEventDetail = async (stageInfo: RoundStage | EliminationStage) => {
  console.log(stageInfo);
  uni.navigateTo({
    url: `/pages/eventDetail/eventDetail?id=${stageInfo.id}&type=${stageInfo.type}`,
  });
};
const removeStage = async (id: number) => {
  await removeById(id.toString());
  props.onChange();
};
onLoad(async () => {
  await initFormModel();
});
const checkDetail = (stageItem) => {
  // goEventDetail(stageItem)
  //saveData.stageEvents = saveData.stageEventTypes
  if (stageItem.type === StageTypeEnum.Loop) {
    showRoundStagePopup.value = true;
    roundFormModel.value = stageItem;
    if (stageItem.stageEvents && stageItem.stageEvents.length) {
      roundFormModel.value.stageEventTypes = stageItem.stageEvents
        .map((v) => EventTypeText[v.type])
        .join(",");
    }
    roundFormReadonly.value = true;
  } else {
    showEliminationPopup.value = true;
    eliminationFormModel.value = stageItem;
    if (stageItem.stageEvents && stageItem.stageEvents.length) {
      roundFormModel.value.stageEventTypes = stageItem.stageEvents
        .map((v) => EventTypeText[v.type])
        .join(",");
    }
    eliminationFormReadonly.value = true;
  }
};
</script>
